//
//  ReplayView.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/26.
//

#import "ReplayView.h"
#import "CommonUtil.h"
#import "ReplayCellView.h"

@interface ReplayView()


@property (strong, nonatomic) UIButton * findAllBtn;

@property (strong, nonatomic) NSMutableArray * replayCellArr;

@end
@implementation ReplayView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
       self.backgroundColor = RGB(243.0, 243.0, 243.0);
        [self addSubview:self.findAllBtn];
        self.layer.cornerRadius = AD(3);
        self.replayCellArr = [NSMutableArray array];
        for (NSInteger i = 0; i < 3; i++) {
            [self.replayCellArr addObject:[ReplayCellView new]];
        }
    }
    return self;
}


-(void)setModel:(MessageModel *)model{
    _model = model;
    for (ReplayCellView *cellView in self.replayCellArr) {
        [cellView removeFromSuperview];
    }
    
    CGFloat y = 0;
    CGFloat count = model.replayList.count;
    for (NSInteger i = 0; i < count; i++) {
        if (i < 3) {
            MessageModel *cellModel = model.replayList[i];
            ReplayCellView *cellView = self.replayCellArr[i];
            cellView.frame = CGRectMake(0, y, self.width, cellModel.replayCellHeight);
            cellView.model = cellModel;
            [self addSubview:cellView];
            if (i == 2) {
                self.findAllBtn.top = cellView.bottom;
            }
            y = cellView.bottom;
            //cellView.backgroundColor = i % 2 ? [UIColor blueColor] : [UIColor yellowColor];
        }
    }
    self.findAllBtn.top = y;
    
}


-(UIButton *)findAllBtn{
    if (!_findAllBtn) {
        _findAllBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_findAllBtn setTitle:@"查看全部回复" forState:UIControlStateNormal];
        _findAllBtn.titleLabel.font = [UIFont systemFontOfSize:AD(13)];
        [_findAllBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
        [_findAllBtn setImage:[UIImage imageNamed:@"icon_findall"] forState:UIControlStateNormal];
        _findAllBtn.frame = CGRectMake(AD(10),AD(170) + AD(5) , AD(150), AD(25));
        _findAllBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, AD(-135));
        _findAllBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, AD(50));
    }
    return _findAllBtn;
}

@end
